window.onload = function () {
  let phone = false;
  let psd = false;
  let psds = false
  let inputs = document.querySelectorAll("input");
  let btn = document.querySelector('button');
  console.log(inputs)
  //手机验证
  inputs[0].oninput = function () {
    let Reg = /^1[345789]\d{9}$/;
    if (Reg.test(this.value)) {
      axios.get(checkusernameAPI, {
          params: {
            username: inputs[0].value
          },
        })
        .then((Reg) => {
          let obj = Reg.data
          console.log(obj);
          inputs[0].nextElementSibling.innerHTML = obj.msg;
          if (obj.code == 1) {
            phone = true;
          } else {
            phone = false
          }
        })


    } else {
      phone = false;
      this.nextElementSibling.innerHTML = '&nbsp;&nbsp;请输入有效的手机号码&nbsp;&nbsp;';
    }
  }
  isNull(inputs[0])
  //密码框
  inputs[2].oninput = function () {
    let Reg = /^.{6,16}$/
    if (Reg.test(this.value)) {
      psd = true
      this.nextElementSibling.innerHTML = '&nbsp;&nbsp;格式正确&nbsp;&nbsp;';

      inputs[3].disabled = false
    } else {
      psd = false
      this.nextElementSibling.innerHTML = '&nbsp;&nbsp;除了换行符之外的6-16位字符&nbsp;&nbsp;';
      inputs[3].disabled = false
    }
  }
  isNull(inputs[2])
  //确认密码
  inputs[3].oninput = function () {
    let Reg = /^.{6,16}$/;
    if (this.value == inputs[2].value) {
      psds = true
      this.nextElementSibling.innerHTML = '&nbsp;&nbsp;格式正确&nbsp;&nbsp;';
    } else {
      psds = false
      this.nextElementSibling.innerHTML = '&nbsp;&nbsp;两次密码输入不一致&nbsp;&nbsp;';
    }
  }

  btn.onclick = function () {
    // 判断 要不要提交
    if (
      phone &&
      psd
    ) {
      let username = inputs[0].value
      let password = inputs[2].value
      axios
        .get(regAPI, {
          params: {
            username: username,
            password
          },
        })
        .then((res) => {
          let {
            data
          } = res;
          console.log(data);
          // alert(data.msg);
          if (data.code == 1) {
            location.href = "../denglu.html";
            // 13246579871
          }
        });
    } else {}


  }
}

function isNull(obj) {
  obj.onblur = function () {
    if (obj.value == "") {
      isobj = false;
      this.nextElementSibling.innerHTML = '&nbsp;&nbsp;参数不能为空&nbsp;&nbsp;'
    }
  }
};